import babel from "rollup-plugin-babel"; //代码转换：es6->es5
import commonjs from "rollup-plugin-commonjs"; //支持commonjs导入导出
import { uglify } from "rollup-plugin-uglify"; //代码压缩
import npm from "rollup-plugin-node-resolve"; //支持第三方库的导入，如：lodash
import postcss from "rollup-plugin-postcss";
import serve from 'rollup-plugin-serve';
import copy from 'rollup-plugin-copy';

const isProduction = process.env.NODE_ENV === "production";
const plugins = [
	commonjs(),
	babel({
		exclude: "node_modules/**",
	}),
	npm(),
	postcss(
		{
			extract: 'css/style.css'
		}
	),
	copy({
		targets: [
			{ src: './src/assets/font', dest: 'dist' } // 复制static目录到dist目录
		],
		flatten: true // 可选，将所有文件复制到flat目录结构
	})
]

if (isProduction) {
	plugins.push(uglify())
} else {
	plugins.push(serve({
		contentBase: ['dist'],
		port: 8080
	}))
}
export default {
	input: "./src/index.js",
	output: {
		file: 'dist/bundle.js',
		format: "cjs", // 输出格式，支持 'amd', 'cjs', 'es', 'iife' 或 'umd'
	},
	sourceMap: "inline",
	plugins
};
